﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DBUtility;
using System.Data.SqlClient;

public partial class BasicBase_SocLinke_SocLinkeEdit : System.Web.UI.Page
{
    public String infoname = "";
    public String infoid2 = "";
    public String TelPhone = "";
    public String Fax = "";
    public String Address = "";
    public String mark = "";
    public String sortid = "";
    public String LinkPeople = "";
    public DataTable PropData;
    public bool View = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (PublicWeb.IsSubEdit(Request))
        {
            String infoid = PublicFunction.GetRequstQueryString(Request, "infoid");
            SQLHelper db = new SQLHelper();
            DataTable dt = db.GetDataTableBySqlStr("select * from SocLinke where INFOID='"+infoid+"'");
            if (dt.Rows.Count > 0)
            {
                infoname = dt.Rows[0]["InfoName"].ToString();
                infoid2 = dt.Rows[0]["INFOID"].ToString();
                TelPhone = dt.Rows[0]["TelPhone"].ToString();
                Fax = dt.Rows[0]["Fax"].ToString();
                Address = dt.Rows[0]["Address"].ToString();
                mark = dt.Rows[0]["mark"].ToString();
                sortid = dt.Rows[0]["SortID"].ToString();
                PropData = GetProp(infoid2);
                LinkPeople = dt.Rows[0]["LinkPeople"].ToString();
            }
        }
        if (PublicFunction.GetRequstQueryString(Request, "act") == "view")
        {
            String infoid = PublicFunction.GetRequstQueryString(Request, "infoid");
            SQLHelper db = new SQLHelper();
            DataTable dt = db.GetDataTableBySqlStr("select * from SocLinke where INFOID='" + infoid + "'");
            if (dt.Rows.Count > 0)
            {
                infoname = dt.Rows[0]["InfoName"].ToString();
                infoid2 = dt.Rows[0]["INFOID"].ToString();
                TelPhone = dt.Rows[0]["TelPhone"].ToString();
                Fax = dt.Rows[0]["Fax"].ToString();
                Address = dt.Rows[0]["Address"].ToString();
                mark = dt.Rows[0]["mark"].ToString();
                sortid = dt.Rows[0]["SortID"].ToString();
                LinkPeople = dt.Rows[0]["LinkPeople"].ToString();
                PropData = GetProp(infoid2);
            }
            View = true;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SQLHelper db = new SQLHelper();
        if (db.SqlExec("update SocLinke set LinkPeople='" + PublicFunction.GetRequstForm(Request, "LinkPeople") + "',InfoName='" + PublicFunction.GetRequstForm(Request, "InfoName") + "',TelPhone='" + PublicFunction.GetRequstForm(Request, "TelPhone") + "',Address='" + PublicFunction.GetRequstForm(Request, "Address") + "',Fax='" + PublicFunction.GetRequstForm(Request, "Fax") + "',mark='" + PublicFunction.GetRequstForm(Request, "mark") + "',sortid='" + PublicFunction.GetRequstForm(Request, "sort01") + "' where INFOID='" + PublicFunction.GetRequstForm(Request, "infoid") + "'"))
        {
            bool r = true;
            int i=0;
            db.SqlExec("delete from SocProp where SocLinkeID='" + PublicFunction.GetRequstForm(Request, "infoid") + "'");
            while ((PublicFunction.GetRequstForm(Request, "sSocProp" + i.ToString()) != "")||(i<10))
            {
                if (PublicFunction.GetRequstForm(Request, "sSocProp" + i.ToString()) != "")
                if (!db.SqlExec("INSERT INTO [SocProp]([SocPropName],[SocPropCount],[SocPropUnit],[SocLinkeID])VALUES('" + PublicFunction.GetRequstForm(Request, "sSocProp" + i.ToString()) + "','" + PublicFunction.GetRequstForm(Request, "nSocProp" + i.ToString()) + "','" + PublicFunction.GetRequstForm(Request, "dSocProp" + i.ToString()) + "','" + PublicFunction.GetRequstForm(Request, "infoid") + "')"))
                    r = false;
                i++;
            }
            if(r)
            Response.Redirect("SocLinkeList.aspx");
        }
    }

    DataTable GetProp(String infoID)
    {
        SQLHelper db = new SQLHelper();
        return db.GetDataTableBySqlStr("SELECT *  FROM [SocProp] where SocLinkeID='"+infoID+"'");
    }
}
